package cn.jiyun.controller;
//import cn.jiyun.common.AutoLogs;
import cn.jiyun.common.config.Result;
import cn.jiyun.entity.Sbgl;
import cn.jiyun.entity.Sblx;
import cn.jiyun.service.ISbglService;
import cn.jiyun.service.ISblxService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-28
 */
@RestController
@RequestMapping("/sbgl")
@CrossOrigin //允许跨域
public class SbglController {

    @Autowired
    private ISbglService sbglService;

    @Autowired
    private ISblxService sblxService;

    @RequestMapping("/findPage")
    public Result findPage(Integer pageNum, Integer pageSize, @RequestBody Sbgl sbgl){
        Page page=sbglService.findPage(pageNum,pageSize,sbgl);
        return Result.ok(page);
    }

    @RequestMapping("/xialaList")
    public Result xialaList(){
        List<Sblx> sblxList = sblxService.list();
        return Result.ok(sblxList);
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        Sbgl sbgl = sbglService.getByIdtc(id);
        return Result.ok(sbgl);
    }

    @RequestMapping("/add")
//    @AutoLogs(value = "设备管理添加操作", loggingtype  = 0)
    public Result add(@RequestBody Sbgl sbgl){
        if (sbgl.getId()==null){
            sbgl.setCreateds("admin");
            sbgl.setCtime(LocalDateTime.now());
            sbgl.setYid(1);
            sbgl.setPho("18888888888");
            sbglService.save(sbgl);
            return Result.ok("添加成功！");
        }else{
            sbglService.updateById(sbgl);
            return Result.ok("修改成功！");
        }
    }

    @RequestMapping("/zhuangtai")
//    @AutoLogs(value = "设备管理更新操作", loggingtype  = 0)
    public Result zhuangtai(Integer id,Integer status){
        Sbgl sbgl = new Sbgl().setId(id).setStatus(status);
        sbglService.updateById(sbgl);
        return Result.ok("解绑成功！");
    }

    @RequestMapping("/deleteById")
//    @AutoLogs(value = "设备管理删除操作", loggingtype  = 0)
    public Result deleteById(Integer id){
        sbglService.removeById(id);
        return Result.ok("删除成功！");
    }
}
